package com.hd.crdao.activity;

import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.hd.crdao.R;
import com.hd.crdao.base.BaseSecondActivity;
import com.hd.crdao.bean.MessageBean;
import com.hd.crdao.config.Constants;
import com.hd.crdao.utils.MyToast;
import com.hd.crdao.view.ExpandHeadView;
import com.hd.crdao.wrapper.CustomCallback;
import com.zhy.http.okhttp.OkHttpUtils;

import butterknife.BindView;

/**
 * @author Programming
 * @date 2017/10/18 0018
 */

public class DelayPayMoneyActivity extends BaseSecondActivity implements View.OnClickListener {
    @BindView(R.id.delayPayMoney_head)
    ExpandHeadView mDelayPayMoneyHead;
    public static final int UNAPPLY_DELAY_PAY = 0;
    public static final int SUCCESS_DELAY_PAY = 1;
    public static final int APPLYING_DELAY_PAY = 3;
    public static final int FAILED_DELAY_PAY = 5;
    @BindView(R.id.applyDelayTip)
    TextView mApplyDelayTip;
    @BindView(R.id.apply)
    Button mApply;
    @BindView(R.id.veBrand)
    TextView mVeBrand;
    @BindView(R.id.vcCredit)
    TextView mVcCredit;
    @BindView(R.id.vcRate)
    TextView mVcRate;
    @BindView(R.id.fkDate)
    TextView mFkDate;

    @Override
    protected int setContentView() {
        return R.layout.activity_delaypaymoney;
    }

    @Override
    protected ExpandHeadView setExpandHeadView() {
        return mDelayPayMoneyHead;
    }

    @Override
    protected void initView() {
        int state = getIntent().getIntExtra("state", UNAPPLY_DELAY_PAY);
        switch (state) {
            case UNAPPLY_DELAY_PAY:
                mDelayPayMoneyHead.getHeadViewMidText().setText("申请展期");
                mApplyDelayTip.setVisibility(View.GONE);
                mApply.setVisibility(View.VISIBLE);
                mApply.setOnClickListener(this);
                break;
            case APPLYING_DELAY_PAY:
                mDelayPayMoneyHead.getHeadViewMidText().setText("申请展期");
                mApplyDelayTip.setVisibility(View.VISIBLE);
                mApplyDelayTip.setText("审核中...");
                mApply.setVisibility(View.GONE);
                break;
            case FAILED_DELAY_PAY:
                mDelayPayMoneyHead.getHeadViewMidText().setText("申请展期");
                mApplyDelayTip.setVisibility(View.VISIBLE);
                mApplyDelayTip.setText("审核不通过");
                mApply.setVisibility(View.GONE);
                break;
            case SUCCESS_DELAY_PAY:
                mDelayPayMoneyHead.getHeadViewMidText().setText("展期成功");
                mApplyDelayTip.setVisibility(View.GONE);
                mApply.setVisibility(View.GONE);
                break;
        }
        initData();
    }

    private void initData() {
        String veBrand = getIntent().getStringExtra("veBrand");
        String vcCredit =getIntent().getStringExtra("vcCredit");
        String vcRate =  getIntent().getStringExtra("vcRate");
        String fkDate =  getIntent().getStringExtra("fkDate");
        mVeBrand.setText(veBrand);
        mVcCredit.setText(vcCredit);
        mVcRate.setText(vcRate);
        mFkDate.setText(fkDate);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.apply:
                applyDelayPay();
                break;
            default:
                break;
        }
    }

    /**
     * 申请展期
     */
    private void applyDelayPay() {
        String vehCreditId = getIntent().getStringExtra("vehCreditId");
        OkHttpUtils.post().url(Constants.COMPLETEEXTEND_URL)
                .addParams("sign", Constants.SIGN)
                .addParams("vehCreditId", vehCreditId).build().execute(new CustomCallback<MessageBean>() {

            @Override
            public void onResponse(MessageBean messageBean, int id) {
                if (messageBean.getSuccess() == 0) {
                    MyToast.show(messageBean.getMessage());
                    finish();
                } else {
                    MyToast.show(messageBean.getMessage());
                }
            }
        });
    }


}
